/*******************************************************************************
 * Copyright 2011 alipay.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.alipay.platform.data.impl.orm;

import java.util.ArrayList;

import android.test.AndroidTestCase;

import com.alipay.platform.data.impl.DataAccessor;
import com.alipay.platform.data.impl.orm.mock.Book;
import com.alipay.platform.data.impl.orm.mock.User;

/**
 * @author sanping.li@alipay.com
 *
 */
public class TestOrmDataAccessor extends AndroidTestCase {
	private DataAccessor mDataAccessor;
	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
		mDataAccessor = new OrmDataAccessor(getContext());
	}

	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
	}

	
	public void testWrite(){
		Book book = new Book();
		book.setAuthor("sanping.li");
		book.setHot(true);
		book.setName("android dev");
		book.setPrize(100);
		
		User user = new User();
		user.setName("sanping.li");
		user.setBook(book);
		try {
			long id = mDataAccessor.write(user);
			assertTrue("OK", id!=-1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void testRead(){
		try {
			ArrayList<Object> arrayList = mDataAccessor.read(User.class, null, null, null);
			assertTrue("OK", arrayList.size()>0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
